package com.mxgraph.examples.swing.chart;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.DefaultXYDataset;

import javax.swing.*;
import java.awt.*;

/**
 * Created by Arseniy Nazarov on 17.10.14.
 */
public class ChartManager {

    public static void showChart(double[] x, double[][] transposedY, String[] legend) {

        //Solution matlabSolution = new Solution(x, transposedY);


        JFrame jFrame = new JFrame("Energetics chart");
        jFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        //ismaPlusForm.getResultTextArea().setText(solution.toString());

        DefaultXYDataset ds = new DefaultXYDataset();
        // double[][] transposedY = matlabSolution.getTransposedY();
        for (int i = 0; i < transposedY.length; i++) {
            double[] y = transposedY[i];
            double[][] xy = new double[][]{x, y};
            ds.addSeries(legend[i], xy);
        }
        JFreeChart chart = ChartFactory.createXYLineChart("",
                "X", "Y", ds, PlotOrientation.VERTICAL, true, true,
                false);
        ChartPanel cp = new ChartPanel(chart);
        jFrame.add(cp);

        //jFrame.add(ismaPlusForm.getMainPanel());
        jFrame.pack();
        Dimension screeSize = Toolkit.getDefaultToolkit().getScreenSize();
        jFrame.setLocation(screeSize.width/2-jFrame.getSize().width/2, screeSize.height/2-jFrame.getSize().height/2);
        jFrame.setVisible(true);
    }

}
